<template>
  <base-breadcrumb>
    <searchData :searchData="searchArr" @search="search"></searchData>

    <a-card>
      <!-- 危险作业列表统计 -->
      <div class="table-operateors mb20">
        <div class="pub-table-select-count" style="margin: 10px 0">
          <a-icon type="info-circle" theme="twoTone" />
          <span>
                        高风险作业许可总数：
                        <a>{{ statistical.total||0 }}</a
                        >个
                    </span>
          <a-divider type="vertical"></a-divider>
          <span>
                        待提交审核：
                        <a>{{ statistical.draft||0 }}</a
                        >个
                    </span>
          <a-divider type="vertical"></a-divider>
          <span>
                        审核中：
                        <a>{{ statistical.submitted||0 }}</a
                        >个
                    </span>
          <a-divider type="vertical"></a-divider>
          <span>
                        审核通过：
                        <a>{{ statistical.past||0 }}</a
                        >个
                    </span>
          <a-divider type="vertical"></a-divider>
          <span>
                        审核不通过：
                        <a>{{ statistical.rejected||0 }}</a>个
                    </span>
        </div>
      </div>
      <list-table
        ref="table"
        size="default"
        rowKey="key"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        showPagination="auto"
      >
                <span slot="operation" slot-scope="text, record">
                    <a @click="detailed(record)">查看</a>
                    <span
                      v-if="
                            record.auditStatus === 'PAST' ||
                            record.auditStatus === 'SUBMITTED' ||
                            record.auditStatus === 'REJECTED'
                      ">
                        <a-divider type="vertical" />
                        <approval-button :status="record.auditStatus" :id="record.id"></approval-button>
                    </span>
                </span>
        <span slot="sort" slot-scope="text, record, index">{{ index + 1 }}</span>
        <span slot="auditStatus" slot-scope="text, record">
                    <list-status
                      :status="record.auditStatus"
                      :isApproval="true"
                      conversion="en"
                      :text="text"
                    ></list-status>
                </span>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>
<script>
import { getDangerWorkList,getDangerWorkListCount } from '@/api/safetySupervision/dangerousOperations'

import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 项目
import SelectTeam from '@/components/Select/SelectTeam' // 项目
import { STable } from '@/components'
const columns = [
  {
    title: '序号',
    dataIndex: 'sort',
    width: 80,  
    scopedSlots: { customRender: 'sort' },
  },
  // {
  //     title: '名称',
  //     dataIndex: 'name',
  // },
  {
    title: '作业类型',
    dataIndex: 'operationType',
    width: 180,   
  },
  {
    title: '分公司',
    dataIndex: 'branchComName',
    width: 180,  
  },
  {
    title: '项目',
    dataIndex: 'projectName',
    width: 180,  
  },
  {
    title: '分包单位',
    dataIndex: 'subcontractName',
    width: 180,  
  },
  {
    title: '班组',
    dataIndex: 'teamName',
    width: 120,  
  },

  {
    title: '申请人',
    dataIndex: 'creatorName',
    width: 80,  
  },
  {
    title: '填报时间',
    dataIndex: 'createTime',
    width: 120,  
  },

  {
    title: '状态',
    dataIndex: 'auditStatus',
    width: 80,  
    scopedSlots: { customRender: 'auditStatus' },
  },
  {
    title: '操作',
    dataIndex: 'operation',
    width:170,
    scopedSlots: { customRender: 'operation' },
  },
]
import { typeListApprova2 } from '@/utils/util'
import { getSelectListByType } from '@/api/safetySupervision/common.js'
import BSelect from '@/components/BComponents/BSelect'
export default {
  name:'a'+Date.now(),    components: {
    STable,
  },
  data() {
    this.columns = columns
    return {
      statistical:{},
      queryParam: {},
      searchArr: [
        {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
        // {
        //   name: '所属分公司',
        //   valueKey: 'branchComId',
        //   type: SelectSubCompany,
        // },
        // {
        //   name: '所属项目',
        //   keyValue: 'branchComId',
        //   valueKey: 'projectId',
        //   type: SelectProject,
        // },
        {
          name: '分包单位',
          keyValue: 'searchQuery._checked',
          valueKey: 'subContractorId',
          type: SelectSubcontractor,
        },
        {
          name: '作业班组',
          keyValue: ['searchQuery._checked', 'subContractorId'],
          valueKey: 'teamId',
          type: SelectTeam,
        },
        // {
        //     name: '作业类别',
        //     value: 'typeId',
        //     type: 'select',
        //     data: [],
        //     attrs: {
        //         showSearch: true,
        //         optionFilterProp: 'children',
        //     },
        // },
        {
          name: '作业类别',
          valueKey: 'typeId',
          type: BSelect,
          data: [],
          showSearch: true,
          optionFilterProp: 'children',
          request: async () => {
            const [err, res] = await getSelectListByType({ type: 21 })
            if (!err) {
              res.data.forEach((item) => {
                item.value = item.id
                item.label = item.name
              })
              return { code: this.SUCCESS_CODE, data: res.data }
            }
            return { code: this.SUCCESS_CODE, data: [] }
          }
        },
        {
          name: '填报人',
          value: 'creatorName',
          type: 'input',
        },
        {
          name: '填报时间',
          value: 'applyTime',
          type: 'dateRange',
        },
        {
          name: '状态',
          value: 'auditStatus',
          type: 'select',
          data: typeListApprova2,
        },
      ],
      loadData: async (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        const [err, res] = await getDangerWorkList(requestParameters)
        this. getDangerWorkListCount(this.queryParam)
        return new Promise((resolve, reject) => {
          if (err) {
            reject(err)
          } else {
            resolve(res)
          }
        })
      },
    }
  },
  mounted() {
  },
  methods: {
    // 危险作业统计
    async getDangerWorkListCount(params){
      const [err, res]  =   await getDangerWorkListCount(params)
      if (!err) {
        this.statistical = res.data;
      }
    },
    //搜索
    search(val = {}) {
      this.queryParam = {
        ...val,
        createTimeBegin:
          (val.applyTime && val.applyTime.length && val.applyTime[0].format('YYYY-MM-DD')) || void 0,
        createTimeEnd:
          (val.applyTime && val.applyTime.length && val.applyTime[1].format('YYYY-MM-DD')) || void 0,
      }
      console.log(this.queryParam)

      this.$refs.table.refresh(true)
    },
    // 查看
    detailed(e) {
      this.$router.push({
        path: 'addHazardousOperation',
        query: {
          id: e.id || '',
        },
      })
    },
  },
}
</script>
